package cn.hello2018.jdbc;

import java.sql.DriverManager;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;

public class DBUtil {
	private static String URL = "jdbc:mysql://localhost:3306/dzshoppingmall";
	private static String USERNAME = "root";
	private static String PASSWORD = "123456";

	private static Connection conn = null;

	static {
		try {
			// 1. 加载数据库驱动
			Class.forName("com.mysql.jdbc.Driver");

			// 2. 获取数据库的连接
			conn = (Connection) DriverManager.getConnection(URL, USERNAME, PASSWORD);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public static Connection getConn() {
		return conn;
	}

	public static void setConn(Connection conn) {
		DBUtil.conn = conn;
	}

}
